Skip to content

Conversation

ferretwithaberet
Copy link
Contributor

@ferretwithaberet ferretwithaberet commented Feb 27, 2020

Description

Added minRow and row properties.

  • minRow: Minimum amount of rows to generate, default is 0.
  • row: Shortcut to have same value for minRow and maxRow.

fix #1172

Checklist

  • Created tests which fail without the change (if possible)
  • All tests passing (yarn test)
  • Extended the README / documentation, if necessary

src/gridstack.js Outdated
var idSeq = 0;

var GridStackEngine = function(column, onchange, float, maxRow, items) {
var GridStackEngine = function(row, column, onchange, float, minRow, maxRow, items) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to have a number of rows, unlike columns which are fixed and special % CSS layout. Min/MaxRow is more than enough to get everything you need. Also maxRow is not that well supported so I don't want to expose 'row' which is a superset. Please take out.

Also adding new param to new GridStackEngine() means all the test cases that use need updating - please fix them (under spec/) and make sure npm test still works after your changes AND the demo/ apps run. I know it's a lot but something I will have to do otherwise and I don't have extra cycle for this feature right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im actually happy that it actually works. Will refactor tomorrow, I also need to get more familiar with the code. Also, is there any reasons why you use var instead of let and const?

Copy link
Member

@adumesny adumesny Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't write that legacy code! I'm actually converting to typescript (and I will have hand pick all those changes since 1.0.0 so minimal changes please!) as I hate JS spaghetti code.

src/gridstack.js Outdated
GridStack.prototype._updateContainerHeight = function() {
if (this.engine._batchMode) { return; }
var row = this.engine.getRow();
var row = this.opts.minRow > this.engine.getRow() ? this.opts.minRow : this.engine.getRow();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't call methods twice! inefficient. either put the minRow in getRow() (see where it's used or here)

@ferretwithaberet
Copy link
Contributor Author

ferretwithaberet commented Feb 28, 2020

I implemented minRow how @adumesny told me to do in the first place. Also, now if row is set, it will replace both the values of minRow and maxRow in opts, essentially making it a shortcut for minRow and maxRow.

GridStack.prototype._updateContainerHeight = function() {
if (this.engine._batchMode) { return; }
var row = this.engine.getRow();
if (row < this.opts.minRow) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, that is the right place to put it. as you can see you can also accomplish this with CSS min-height on the grid div, but setting minRow can be easier for some.

row: parseInt(this.$el.attr('data-gs-row')) || 0,
column: parseInt(this.$el.attr('data-gs-column')) || 12,
maxRow: parseInt(this.$el.attr('data-gs-max-row')) || 0,
minRow: parseInt(this.$el.attr('data-gs-row')) ? parseInt(this.$el.attr('data-gs-row')) : parseInt(this.$el.attr('data-gs-min-row')) || 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please extract this.$el.attr('data-gs-row') into a var right above - easier to read/parse. maybe minRowAttr


opts = opts || {};

// if row property exists, replace minRow and maxRow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move that down - feel weird to be first thing we check... like right after 715 where we set opts values.

* a string (ex: '100px', '10em', '10rem', '10%')
* 0 or null, in which case the library will not generate styles for rows. Everything must be defined in CSS files.
* `'auto'` - height will be calculated to match cell width (initial square grid).
- `row` - number of rows. This is a shortcut of writting `minRow: sameValue, maxRow: sameValue`.
Copy link
Member

@adumesny adumesny Feb 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, but all those need to be alphabetized please. also row should say something like:

row - fixed number of rows which prevents the grid from changing as items are added/removed/moved, Shortcut for setting minRow: N, maxRow: N. default is 0 no constrain. EXPERIMENTAL - see maxRow

@adumesny
Copy link
Member

thanks, the last code version looks a lot better. I'll accept it and tweak the doc.

@adumesny adumesny merged commit c5df96f into gridstack:develop Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to set the number of grid rows
2 participants